package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannelService;
import com.heima.common.exception.CustException;
import com.heima.common.exception.CustomException;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "频道管理api借口" , tags = "频道管理api借口")
@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @ApiOperation(value = "分页条件查询频道列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDTO dto){
        return channelService.findByNameAndPage(dto);

    }


    /**
     * 分页查询
     * @param
     * @return
     */
    @ApiOperation(value = "保存频道")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel){
        return channelService.insert(channel);
    }



    /**
     * 分页查询
     * @param
     * @return
     */
    @ApiOperation(value = "修改频道")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel channel){
        return channelService.update(channel);
    }


    /**
     * 删除查询
     * @param
     * @return
     */
    @ApiOperation(value = "删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return channelService.deleteById(id);
    }




    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }


    /**
     * 根据文章的id查问频道
     * @param id
     * @return
     */
    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(channelService.getById(id));
    }


}
